import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class P1162 {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[][] f = new int[n][n];
        for (int i = 0; i < n; i++) {
            String tmp = br.readLine();
            String[] nums = tmp.split(" ");
            for (int j = 0; j < n; j++) {
                f[i][j] = Integer.parseInt(nums[j]);
            }
        }
        System.out.println();
        for (int i = 0; i < n; i++) {
            if(f[0][i] == 0) f[0][i] = -1;
            if(f[n - 1][i] == 0) f[n - 1][i] = -1;
            if(f[i][0] == 0) f[i][0] = -1;
            if(f[i][n - 1]== 0) f[i][n - 1] = -1;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (f[i][j] == -1) {
                    if (i - 1 >= 0 && f[i - 1][j] == 0) {
                        f[i - 1][j] = -1;
                    }
                    if (i + 1 < n && f[i + 1][j] == 0) {
                        f[i + 1][j] = -1;
                    }
                    if (j - 1 >= 0 && f[i][j - 1] == 0) {
                        f[i][j - 1] = -1;
                    }
                    if (j + 1 < n && f[i][j + 1] == 0) {
                        f[i][j + 1] = -1;
                    }
                }

            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(f[i][j] == -1){
                    System.out.print(0+" ");
                }else if(f[i][j] == 0){
                    System.out.print(2+" ");
                }else{
                    System.out.print(f[i][j]+" ");
                }
            }
            System.out.println();
        }
    }
}
